﻿namespace SuperFind.Converters
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Converters;
    using System.Windows;
    using System.Windows.Markup;
    using System.Windows.Data;
    using System.IO;

    class FileSizeConverter : MarkupExtension, IValueConverter
    {
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string fileSize = null;
            if(value!=null)
            {
                if (File.Exists(value as string))
                {
                    fileSize = new FileInfo(value as string).Length.ToString();
                }
            }
            return fileSize;
            
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}
